^tools/xenstat/xentop/xentop$
^tools/xenstore/testsuite/tmp/.*$
^tools/xenstore/xen$
+^tools/xenstore/xenbus_dev.h$
^tools/xenstore/xenstored$
^tools/xenstore/xenstored_test$
+^tools/xenstore/xenstore-read$
+^tools/xenstore/xenstore-rm$
+^tools/xenstore/xenstore-write$
^tools/xenstore/xs_dom0_test$
^tools/xenstore/xs_random$
^tools/xenstore/xs_stress$
TESTFLAGS= -DTESTING
TESTENV = XENSTORED_ROOTDIR=$(TESTDIR) XENSTORED_RUNDIR=$(TESTDIR)
-all: xen xenstored libxenstore.so
+CLIENTS := xenstore-read xenstore-rm xenstore-write
+CLIENTS_OBJS := $(patsubst xenstore-%,xenstore_%.o,$(CLIENTS))
+
+all: xen xenbus_dev.h libxenstore.so xenstored $(CLIENTS)
testcode: xen xs_test xenstored_test xs_random xs_dom0_test
xen:
ln -sf $(XEN_ROOT)/xen/include/public $@
+xenbus_dev.h:
+ ln -sf $(XEN_ROOT)/linux-2.6-xen-sparse/include/asm-xen/linux-public/xenbus_dev.h $@
+
xenstored: xenstored_core.o xenstored_watch.o xenstored_domain.o xenstored_transaction.o xs_lib.o talloc.o utils.o
$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -lxenctrl -o $@
+$(CLIENTS): xenstore-%: xenstore_%.o
+ $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -lxenctrl -L. -lxenstore -o $@
+
+$(CLIENTS_OBJS): xenstore_%.o: xenstore_client.c
+ $(COMPILE.c) -DCLIENT_$(*F) -o $@ $<
+
xenstored_test: xenstored_core_test.o xenstored_watch_test.o xenstored_domain_test.o xenstored_transaction_test.o xs_lib.o talloc_test.o fake_libxc.o utils.o
$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
tarball: clean
cd .. && tar -c -j -v -h -f xenstore.tar.bz2 xenstore/
-install: xenstored libxenstore.so
+install: libxenstore.so xenstored $(CLIENTS)
$(INSTALL_DIR) -p $(DESTDIR)/var/run/xenstored
$(INSTALL_DIR) -p $(DESTDIR)/var/lib/xenstored
$(INSTALL_DIR) -p $(DESTDIR)/usr/sbin
$(INSTALL_DIR) -p $(DESTDIR)/usr/include
$(INSTALL_PROG) xenstored $(DESTDIR)/usr/sbin
+ $(INSTALL_PROG) $(CLIENTS) $(DESTDIR)/usr/bin
$(INSTALL_DIR) -p $(DESTDIR)/usr/$(LIBDIR)
$(INSTALL_DATA) libxenstore.so $(DESTDIR)/usr/$(LIBDIR)
$(INSTALL_DATA) xs.h $(DESTDIR)/usr/include
--- /dev/null
+/*
+ * This file is subject to the terms and conditions of the GNU General
+ * Public License. See the file "COPYING" in the main directory of
+ * this archive for more details.
+ *
+ * Copyright (C) 2005 by Christian Limpach
+ *
+ */
+
+#include <err.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <xs.h>
+
+static void
+usage(const char *progname)
+{
+#if defined(CLIENT_read)
+ errx(1, "Usage: %s [-h] [-p] key [...]", progname);
+#elif defined(CLIENT_write)
+ errx(1, "Usage: %s [-h] key value [...]", progname);
+#elif defined(CLIENT_rm)
+ errx(1, "Usage: %s [-h] key [...]", progname);
+#endif
+}
+
+int
+main(int argc, char **argv)
+{
+ struct xs_handle *xsh;
+ bool success;
+ int ret = 0;
+#if defined(CLIENT_read)
+ char *val;
+ int prefix = 0;
+#endif
+
+ xsh = xs_domain_open();
+ if (xsh == NULL)
+ err(1, "xs_domain_open");
+
+ while (1) {
+ int c, index = 0;
+ static struct option long_options[] = {
+ {"help", 0, 0, 'h'},
+#if defined(CLIENT_read)
+ {"prefix", 0, 0, 'p'},
+#endif
+ {0, 0, 0, 0}
+ };
+
+ c = getopt_long(argc, argv, "h"
+#if defined(CLIENT_read)
+ "p"
+#endif
+ , long_options, &index);
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 'h':
+ usage(argv[0]);
+ /* NOTREACHED */
+#if defined(CLIENT_read)
+ case 'p':
+ prefix = 1;
+ break;
+#endif
+ }
+ }
+
+ if (optind == argc) {
+ usage(argv[0]);
+ /* NOTREACHED */
+ }
+#if defined(CLIENT_write)
+ if ((argc - optind) % 1) {
+ usage(argv[0]);
+ /* NOTREACHED */
+ }
+#endif
+
+ /* XXX maybe find longest common prefix */
+ success = xs_transaction_start(xsh, "/");
+ if (!success)
+ errx(1, "couldn't start transaction");
+
+ while (optind < argc) {
+#if defined(CLIENT_read)
+ val = xs_read(xsh, argv[optind], NULL);
+ if (val == NULL) {
+ warnx("couldn't read path %s", argv[optind]);
+ ret = 1;
+ goto out;
+ }
+ if (prefix)
+ printf("%s: ", argv[optind]);
+ printf("%s\n", val);
+ free(val);
+ optind++;
+#elif defined(CLIENT_write)
+ success = xs_write(xsh, argv[optind], argv[optind + 1],
+ strlen(argv[optind + 1]), O_CREAT);
+ if (!success) {
+ warnx("could not write path %s", argv[optind]);
+ ret = 1;
+ goto out;
+ }
+ optind += 2;
+#elif defined(CLIENT_rm)
+ success = xs_rm(xsh, argv[optind]);
+ if (!success) {
+ warnx("could not remove path %s", argv[optind]);
+ ret = 1;
+ goto out;
+ }
+ optind++;
+#endif
+ }
+
+ out:
+ success = xs_transaction_end(xsh, ret ? true : false);
+ if (!success)
+ errx(1, "couldn't end transaction");
+
+ return ret;
+}
#include <signal.h>
#include <stdint.h>
#include <errno.h>
+#include <sys/ioctl.h>
#include "xs.h"
#include "xenstored.h"
#include "xs_lib.h"
#include "utils.h"
+#include "xenbus_dev.h"
struct xs_handle
{
int fd;
+ enum { SOCK, DEV } type;
};
/* Get the socket from the store daemon handle.
h = malloc(sizeof(*h));
if (h) {
h->fd = sock;
+ h->type = SOCK;
return h;
}
}
saved_errno = errno;
close(sock);
- free(h);
+ errno = saved_errno;
+ return NULL;
+}
+
+static struct xs_handle *get_dev(const char *connect_to)
+{
+ int fd, saved_errno;
+ struct xs_handle *h = NULL;
+
+ fd = open(connect_to, O_RDONLY);
+ if (fd < 0)
+ return NULL;
+
+ h = malloc(sizeof(*h));
+ if (h) {
+ h->fd = fd;
+ h->type = DEV;
+ return h;
+ }
+
+ saved_errno = errno;
+ close(fd);
errno = saved_errno;
return NULL;
}
return get_socket(xs_daemon_socket_ro());
}
+struct xs_handle *xs_domain_open(void)
+{
+ return get_dev(xs_domain_dev());
+}
+
void xs_daemon_close(struct xs_handle *h)
{
if (h->fd >= 0)
}
/* Send message to xs, get malloc'ed reply. NULL and set errno on error. */
-static void *xs_talkv(struct xs_handle *h, enum xsd_sockmsg_type type,
- const struct iovec *iovec, unsigned int num_vecs,
- unsigned int *len)
+static void *xs_talkv_sock(struct xs_handle *h, enum xsd_sockmsg_type type,
+ const struct iovec *iovec, unsigned int num_vecs,
+ unsigned int *len)
{
struct xsd_sockmsg msg;
void *ret = NULL;
return NULL;
}
+/* Send message to xs, get malloc'ed reply. NULL and set errno on error. */
+static void *xs_talkv_dev(struct xs_handle *h, enum xsd_sockmsg_type type,
+ const struct iovec *iovec, unsigned int num_vecs,
+ unsigned int *len)
+{
+ struct xenbus_dev_talkv dt;
+ char *buf;
+ int err, buflen = 1024;
+
+ again:
+ buf = malloc(buflen);
+ if (buf == NULL) {
+ errno = ENOMEM;
+ return NULL;
+ }
+ dt.type = type;
+ dt.iovec = (struct kvec *)iovec;
+ dt.num_vecs = num_vecs;
+ dt.buf = buf;
+ dt.len = buflen;
+ err = ioctl(h->fd, IOCTL_XENBUS_DEV_TALKV, &dt);
+ if (err < 0) {
+ free(buf);
+ errno = err;
+ return NULL;
+ }
+ if (err > buflen) {
+ free(buf);
+ buflen = err;
+ goto again;
+ }
+ if (len)
+ *len = err;
+ return buf;
+}
+
+/* Send message to xs, get malloc'ed reply. NULL and set errno on error. */
+static void *xs_talkv(struct xs_handle *h, enum xsd_sockmsg_type type,
+ const struct iovec *iovec, unsigned int num_vecs,
+ unsigned int *len)
+{
+ if (h->type == SOCK)
+ return xs_talkv_sock(h, type, iovec, num_vecs, len);
+ if (h->type == DEV)
+ return xs_talkv_dev(h, type, iovec, num_vecs, len);
+ return NULL;
+}
+
/* free(), but don't change errno. */
static void free_no_errno(void *p)
{
* Returns a handle or NULL.
*/
struct xs_handle *xs_daemon_open(void);
+struct xs_handle *xs_domain_open(void);
/* Connect to the xs daemon (readonly for non-root clients).
* Returns a handle or NULL.
return buf;
}
+const char *xs_domain_dev(void)
+{
+ char *s = getenv("XENSTORED_DOMAIN_DEV");
+ return (s ? s : "/proc/xen/xenbus");
+}
+
/* Simple routines for writing to sockets, etc. */
bool xs_write_all(int fd, const void *data, unsigned int len)
{
const char *xs_daemon_socket_ro(void);
const char *xs_daemon_store(void);
const char *xs_daemon_transactions(void);
+const char *xs_domain_dev(void);
/* Simple write function: loops for you. */
bool xs_write_all(int fd, const void *data, unsigned int len);